package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysSignRecord;
import com.gec.model.vo.SysSignRecordQueryVo;
import com.gec.system.service.SysSignRecordService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 签到记录表 前端控制器
 * </p>
 *
 * @author lxj
 * @since 2024-03-07
 */
@Api(tags = "签到记录控制器")
@RestController
@RequestMapping("/admin/system/sysSignRecord")
public class SysSignRecordController {

    @Autowired
    private SysSignRecordService sysSignRecordService;


    @ApiOperation("获取全部")
    @GetMapping("/findAll")
    public Result findAll(){
        List<SysSignRecord> list = this.sysSignRecordService.list();
        return Result.ok(list);
    }

    @ApiOperation("根据id去移除")
    // 测试删除
    @DeleteMapping("/removeSignRecord/{id}")
    public Result removeSignRecord(@PathVariable Long id)
    {
        boolean b = this.sysSignRecordService.removeById(id);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }

    // 分页和条件查询
    @GetMapping("/{page}/{limit}")
    public Result findSignRecordByPageQuery(@PathVariable Long page,
                                            @PathVariable Long limit,
                                            SysSignRecordQueryVo vo)
    {
        //1.创建分页对象
        IPage<SysSignRecord> p1 = new Page<>(page,limit);
        //2.调用方法
        p1 =    this.sysSignRecordService.selectPage(p1,vo);
        //3.返回
        return Result.ok(p1);
    }
    // 添加
    @PostMapping("/addSignRecord")
    public Result addSignRecord(@RequestBody SysSignRecord sysSignRecord)
    {
        boolean res = this.sysSignRecordService.save(sysSignRecord);
        if (res)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 修改
    //1.根据id
    @GetMapping("/findSignRecordById/{id}")
    public Result findSignRecordById(@PathVariable Long id)
    {
        SysSignRecord sysSignRecord = this.sysSignRecordService.getById(id);
        return Result.ok(sysSignRecord);
    }

    // 实现修改
    @PostMapping("/updateSignRecord")
    public Result updateSignRecord(@RequestBody SysSignRecord sysSignRecord)
    {
        boolean b = this.sysSignRecordService.updateById(sysSignRecord);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
    // 批量删除
    @DeleteMapping("/removeSignRecordByIds")
    public Result removeSignRecordByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.sysSignRecordService.removeByIds(ids);

        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }
}



